#!/usr/bin/perl -w

print "Content-type:text/html\n";

$bandwidthFile = $ARGV[0];
$error = "Error: bandwidth html is corrupted!";
$counter = 0;
open($file, "<", $bandwidthFile) or $error = "Error: bandwidth file not found!";

if ( $error =~ "Error: bandwidth html is corrupted!" ) {

while ($line = <$file>) {
    if($line =~ /^(Generated\s\d\d.\w\w\w.\d\d\d\d\s\d\d.\d\d\s\w\w\w)\<BR\>$/) { print $1."\n"; $error = "AOK";}
    if($line =~ /^\<TR>\<TD NOWRAP\>\<A HREF\=\"usage_(\d{6}).html\"\>\<FONT SIZE\=\"-1\"\>(\w{3})\s(\d{4})\<\/FONT\>\<\/A\>\<\/TD\>$/) {
      print $1.'|'.$2.'|'.$3.'|'; $counter = 0; $error = "AOK";}
    if($line =~ /^\<TD ALIGN\=right\>\<FONT SIZE\=\"-1\"\>([\d]+)\<\/FONT\>\<\/TD\>$/) {
      if ($counter == 5) { print $1."\n"; }
      $counter++; $error = "AOK"}
}

}

if (!($error =~ "AOK")) { print $error."\n"; } 

close $file;

exit(5);

